package cn.batch.daemon.jdbc;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oracle.jdbc.driver.OracleTypes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.batch.daemon.hibernate.bean.PbocSummary;
import com.skyon.core.config.BaseJNDIEnv;
import com.skyon.core.jdbc.ConnectionProvider;
/**
 * 存储过程测试类
 * @author pengxn
 *
 */
public class BatchRiskDataStore {
	private static Log logger = LogFactory.getLog(BatchRiskDataStore.class);
	private static ConnectionProvider connectionProvider;
	public static void init() {
		BaseJNDIEnv.init();
		connectionProvider = new JdbcConnectionOracleProvider();
	}
	
	
	/**
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public static List<PbocSummary> queryByIdNuber(String id) throws SQLException {
			init();
			Connection con = null;
			con = connectionProvider.getConnection();
		    CallableStatement sp;  
		    List<PbocSummary>  pbList = new ArrayList<PbocSummary>() ;
		    try {  
		         sp = con.prepareCall("{call TEST_QUERY(?,?)}");  
		         sp.setString(1, id);  
		         sp.registerOutParameter(2, OracleTypes.CURSOR);  
		         sp.execute(); // 执行存储过程  
		         ResultSet rs = (ResultSet) sp.getObject(2); // 获取返回的对象,再将对象转为记录集  3代表哪个参数  
		         while (rs.next()) {  
		        	 PbocSummary pboc= new PbocSummary();
		        	 pboc.setCertno(rs.getString(1));
		        	 pbList.add(pboc);
		         }  
		    } catch (SQLException e) {  
		         e.printStackTrace();  
		         logger.error("查询存储过程失败:" , e);
		    }  
		 return pbList;
	}
   /**
    * 
    * 根据barthno删除数据
    * @param date
    * @throws SQLException
   */
	public static void deleteBatchRiskDataByBachNo(String date) throws SQLException {
			init();
			Connection con = null;
			con = connectionProvider.getConnection();
		    CallableStatement sp;  
		    try {  
		         sp = con.prepareCall("{call RISK_DE_BATCH_RISK_DATA(?)}");  
		         sp.setString(1, date);  
		         sp.execute(); // 执行存储过程  
		    } catch (SQLException e) {  
		         e.printStackTrace();  
		         logger.error("存储过程调用失败:" , e);
		    }  
	}


}
	
	
	
	
	
	
	



